$(function(){
	var isflag=$("#isflag").val();
	if(isflag==undefined||isflag==null||isflag==''||isflag==false||isflag=='false'){
		$("#radio1").attr("checked", "checked"); 
	}
	else{
		$("#radio2").attr("checked", "checked"); 
	}
	$("#cancleBut").click(function(){
		parent.$('#dlg').window('close');
		parent.$(document.body).remove()
	});
	var codelength=$('#devicename').width();
	$('#shopid').validatebox({
		required: true,
	    tipPosition:'top',
	    deltaX:codelength/4
	});
	$('#devicemodel').validatebox({
		required: true,
	    tipPosition:'top',
	    deltaX:codelength/4
	});
	$('#deviceprice').validatebox({
		required: true,
	    tipPosition:'top',
	    deltaX:codelength/4,
	    validType: 'intOrFloat',
	});
	$('#remark').validatebox({
	    required: false,
	    tipPosition:'top',
	    validType: {maxLength:[255]},
	    deltaX:codelength/4
	});
	$('#repair').validatebox({
	    required: false,
	    tipPosition:'top',
	    validType: {maxLength:[255]},
	    deltaX:codelength/4
	});
	$('#buildtime').datebox({
		required:true,
		 tipPosition:'top',
		 deltaX:codelength/4
	}); 
	if($("#build").val()!=''){
		var time=Common.formatterDate($("#build").val());
		$('#buildtime').datebox('setValue',time);
	}
	$('#shopid').combobox({
		 url:'/shop/getCombobox',
		 valueField:'id',
		 textField:'text',
	});
	$("#devicemodel").combobox({
		 url:'/model/getCombobox',
		 valueField:'id',
		 textField:'text',
	});
	$('#devicename').validatebox({
	    required: true,
	    tipPosition:'top',
	    deltaX:codelength/4
	});
	//提交表单
	$("#submitBut").click(function(){
		$("#shopid").val($('#shopid').combobox('getValue'));
		if($("#shopid").val()==''||$("#shopid").val()==undefined){
			$.messager.alert('失败','门店不能为空','error');
			return;
		}
		$("#devicemodel").val($('#devicemodel').combobox('getValue'));
		if($("#devicemodel").val()==''||$("#devicemodel").val()==undefined){
			$.messager.alert('失败','型号不能为空','error');
			return;
		}
		$("#form").form('submit',{
			url:'/device/updateDevice',
			onSubmit:function(){
		        return $(this).form('validate');
		    },
		    success:function(data){
		    	var jdata=$.parseJSON(data); 
		        if(jdata.code==200){
		        	$.messager.alert('成功','修改成功','info',function(){
		        		parent.$('#dlg').window('close');
		        		window.parent.refreshTab("设备管理");
		        	});
		        }
		        else{
		        	$.messager.alert('失败',jdata.msg,'error');
		        }
		    }
		});
	})
})